package Kuang;

/**
 * description:
 * author:zcx
 * lenovo
 * 时间：2022.02.09.19.03
 */
//观察线程状态
public class Demo10 {
    public static void main(String[] args) {
        var t = new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("//////");
        });
        //观察状态
        Thread.State state=t.getState();
        System.out.println(state);
        //观察启动后
        t.start();
        state=t.getState();
        System.out.println(state);//Run
        while (state!=Thread.State.TERMINATED){//只要线程不终止，就一直输出状态
            try {
                Thread.sleep(100);
                state=t.getState();//更新线程状态
                System.out.println(state);//输出状态
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

}
